package my.convert;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class TestClass {
	public static Logger logger = LoggerFactory.getLogger(TestClass.class);
	public static void main(String[] args) {
		Map2Bean instance = Map2Bean.getInstance();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id2", "2");
		map.put("name", "hello");
		map.put("doubleVal", "112.3");
		map.put("dateVal", "2018-07-13 02:02:02");
		map.put("intArr[0]", "22");
		map.put("intArr[1]", "222");
		map.put("father.id", "3");
		map.put("son2[0].id", "10");
		map.put("son2[2].id", "12");
		map.put("son2[0].name", "name10");
		map.put("son2[1].id", "11");
		map.put("son2[2].name", "name12");
		map.put("son2[1].name", "name11");
		map.put("son3[b].id", "3000");
		map.put("son3[a].name", "son3_name");
		map.put("mapstring[b]", "mapString_b");
		map.put("strArr[0]", "mapString_b");
		map.put("strArr[2]", "mapString_b2");
		map.put("doubleArr[2]", "23.5");

		try {
          //性能测试
			long time = new Date().getTime();
			for (int i = 0; i < 10000; i++) {
				Person person = instance.getBean(Person.class, map);
				logger.debug(person.toString());
			}
			logger.debug( "转一万次耗时：{} ms ", (new Date().getTime() - time));
			for (int i = 0; i <1; i++) {
				time = new Date().getTime();
				Person bean = instance.getBean(Person.class, map);
				logger.debug("转一次耗时：{} ms ", (new Date().getTime() - time));
				logger.debug("转person:\n {}",bean.toString());
				logger.debug("__________________________________________________");
				Person2 bean2 = instance.getBean(Person2.class, map);
				logger.debug("转person2:\n {}",bean2.toString());
				logger.debug("__________________________________________________");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
